package com.msb.serviceprice.controller;


import com.msb.commons.dto.PriceRule;
import com.msb.commons.response.ResponseResult;
import com.msb.serviceprice.service.PriceRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chshh
 * @since 2022-11-06
 */
@RestController
@RequestMapping("/price-rule")
public class PriceRuleController {
    @Autowired
    private PriceRuleService priceRuleService;

    @PostMapping("/add")
    public ResponseResult add(@RequestBody PriceRule priceRule){

        return priceRuleService.add(priceRule);
    }

    @PostMapping("/edit")
    public ResponseResult edit(@RequestBody PriceRule priceRule){

        return priceRuleService.edit(priceRule);
    }

    @GetMapping("/get-last-version")
    public ResponseResult<PriceRule> getLastVersion(@RequestParam String  fareType){

        return priceRuleService.getLastVersion(fareType);
    }

    @GetMapping("/is-new")
    public ResponseResult<Boolean> isNew(@RequestParam String  fareType,@RequestParam Integer fareVersion){

        return priceRuleService.isNew(fareType,fareVersion);
    }

    /**
     * 根据城市编码和车型查询计价规则是否存在
     * @param priceRule
     * @return
     */
    @PostMapping("/if-exists")
    public ResponseResult<Boolean> ifExists(@RequestBody PriceRule priceRule){

        return priceRuleService.ifExists(priceRule);
    }
}

